package com.webapp.dao;

import java.math.BigDecimal;
import java.util.Calendar;

import org.apache.log4j.Logger;
import org.hibernate.SQLQuery;
import org.springframework.stereotype.Repository;

import com.webapp.domain.entity.LoginCount;
import com.webapp.domain.entity.User;
@Repository("loginCountDAO")
public class LoginCountDAO extends AbstractDAO<LoginCount>{
	protected Logger logger = Logger.getLogger(this.getClass());
	/**
	 * 查询用户最后一次登录时间
	 * @param userId
	 * @return 时间字符串
	 */
	public String getMaxDateLoginCount_user(long userId){
		String sql = "SELECT MAX(CREATE_DATE) FROM LOGIN_COUNT WHERE user_id=?";
		SQLQuery query = getSession().createSQLQuery(sql);
		query.setParameter(0, userId);
		Object obj = query.uniqueResult();
		if (obj == null) {
			return null;
		}else{
			return String.valueOf(obj);
		}
	}
	/**
	 * 查询咨询师最后一次登录时间
	 * @param userId
	 * @return 时间字符串
	 */
	public String getMaxDateLoginCount_counselor(long counselorId){
		String sql = "SELECT MAX(CREATE_DATE) FROM LOGIN_COUNT WHERE counselor_id=?";
		SQLQuery query = getSession().createSQLQuery(sql);
		query.setParameter(0, counselorId);
		 Object obj = query.uniqueResult();
		 if (obj == null) {
			return null;
		}else{
			return String.valueOf(obj);
		}
		
	}
	
	
	
	
	
}
